package com.csit.common;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.csit.entity.User;

/**
 * 
 * @Description: 登录拦截器
 * @Copyright: 福州骏华信息有限公司 (c)2012
 * @Created Date : 2012-9-18
 * @Author lys
 * @Vesion 1.0
 */
public class LoginVerifyFilter implements Filter {

	public void destroy() {

	}

	public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;
		String path = request.getRequestURI().toString();
		if (path.contains("login.html")) {
			chain.doFilter(req, res);
		} else {
			Object id = request.getSession().getAttribute(User.LOGINID);
			if (id != null) {
				chain.doFilter(req, res);
			} else {
				response.sendRedirect("login.html");
			}
			chain.doFilter(req, res);
		}
	}

	public void init(FilterConfig arg0) throws ServletException {

	}

}
